

function getImage() {
    $.ajax({
        type: "post",
        url: "/ylt/shop_image",
        data: {"shopId": "5470"},
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var arr = new Array();
            var test = $("#test");
            test.empty();
            $.each(res.data,function (i,item){
               // arr.push("<div><img src="+item+"></div>");
                arr.push("<div><a href ="+item.URL+"><img src="+item.IMAGE+"></a></div>");
            });
            $(arr.join('')).appendTo(test);


        },
        error: function () {
            alert('error!')
        }
    });
};


function getNews() {
    $.ajax({
        type: "post",
        url: "/ylt/news",
        data: {"shopId": "5470"},
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var arr = new Array();
            var test = $("#test");
            test.empty();
            $.each(res.data,function (i,item){
                arr.push("<div><a href ="+item.URL+"><img src="+item.LITIMG+"></a></div>");
                arr.push("<div>"+item.TITLE+"</div>");
                arr.push("<div>"+item.INTRO+"</div>");
            });
            $(arr.join('')).appendTo(test);


        },
        error: function () {
            alert('error!')
        }
    });
};

function binging_wx() {
    $.ajax({
        type: "post",
        url: "/ylt/binging_wx",
        data: {"u_account": "162963", "u_password": "123321", "wx_id": "test_wxid"},
        dataType: "json",
        success: function (res) {
            alert(res.msg)

        },
        error: function () {
            alert('error!')
        }
    });
}

function getYlt_customerInfo() {
    $.ajax({
        type: "post",
        url: "/ylt/getYlt_customerInfo",
        data: {"wx_id": "test_wxid"},
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var arr = new Array();
            var test = $("#test");
            test.empty();

                arr.push("<div>"+res.data.NAME+"</div>");
                arr.push("<div>"+res.data.CUST_NAME+"</div>");

            $(arr.join('')).appendTo(test);


        },
        error: function () {
            alert('error!')
        }
    });
};


function getYlt_orders_header_fk() {
    $.ajax({
        type: "post",
        url: "/ylt/getYlt_orders_header_fk",
        data: JSON.stringify({"SHOP_CUST_ID": "150372101132459","CUST_ID": "1504690576742135","ORDER_TYPE":"3","PAY_STATE":"1","pageNum":1,"pageSize":100
         }),
        contentType:"json/application",
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var trs = new Array();
            var test = $("#orders_heard");
            test.empty();
            $.each(res.data.list,function (i,item){
                trs.push("<tr>");
                trs.push('<td><div class="order" >'+ (i+1) + '</div></td>');
                trs.push("<td><div ><a onclick='getYlt_Order_Item(\""+item.id+"\",\""+item.B2B_ORDER_NUMBER+"\")' >"+item.id +"</a></div></td>");
                trs.push("<td><div >"+item.state +"</div></td>");
                trs.push("<td><div >"+item.orderProductTotal +"</div></td>");
                trs.push("<td><div >"+item.orderProductCount +"</div></td>");
                trs.push("<td><div >"+item.time +"</div></td>");
                trs.push("<td><div >"+item.goodsList +"</div></td>");
                if (item.SO_ZT=='23') {

                    trs.push("<td><div ><a onclick='ylt_updateOrderZT(\""+item.B2B_ORDER_NUMBER+"\",\""+"8"+"\")' >取消</a></div></td>");
                }
                if (item.SO_ZT=='6') {
                    if(item.PAY_STATE!='Y') {
                        trs.push("<td><div ><a onclick='ylt_signOrder(\"" + item.B2B_ORDER_NUMBER + "\")' >签收付款</a></div></td>");
                    }else{
                        trs.push("<td><div ><a onclick='ylt_updateOrderZT(\"" + item.B2B_ORDER_NUMBER +"\",\""+"7"+ "\")' >签收</a></div></td>");
                    }
                }
                if (item.SO_ZT=='7') {
                    if(item.PAY_STATE!='Y') {
                        trs.push("<td><div ><a onclick='ylt_signOrder(\"" + item.B2B_ORDER_NUMBER + "\")' >付款</a></div></td>");
                    }else{
                        trs.push("<td><div >"+"已完成" +"</div></td>");
                    }
                }
                else {
                    trs.push("<td><div >"+item.SO_ZT +"</div></td>");
                }

                trs.push("<td><div >"+item.PAY_STATEZ +"</div></td>");
                trs.push("</tr>");
            });
            $(trs.join('')).appendTo(test);


        },
        error: function () {
            alert('error!')
        }
    });
};

function getYlt_orders_line(b2b_order_number) {
    getYlt_orders_line_mx(b2b_order_number);
    $('#myModal').modal({
        keyboard: true
    });
    $('#myModal').modal('show');
};

function getYlt_Order_Item(b2b_order_number) {
    getYlt_orders_line_mx(b2b_order_number);
    $('#myModal').modal({
        keyboard: true
    });
    $('#myModal').modal('show');
};

function getYlt_orders_line_mx(b2b_order_number) {
    $.ajax({
        type: "post",
        url: "/ylt/getYlt_Order_Item",
        data: {"b2b_order_number": b2b_order_number,"pageNum":1,"pageSize":100},
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var trs = new Array();
            var test = $("#orders_line");
            test.empty();
            $.each(res.data.list,function (i,item){
                trs.push("<tr>");
                trs.push('<td><div class="order" >'+ (i+1) + '</div></td>');
                trs.push("<td><div >"+item.T_ITEM_NAME +"</div></td>");
                trs.push("<td><div >"+item.ORDER_QTY +"</div></td>");
                trs.push("<td><div >"+item.UNIT_PRICE +"</div></td>");
                trs.push("</tr>");
            });
            $(trs.join('')).appendTo(test);


        },
        error: function () {
            alert('error!')
        }
    });
};


function getSessionKeyOropenid() {
    $.ajax({
        type: "post",
        url: "/ylt/getSessionKeyOropenid",
        data: {"code": "071nGB9v1pS11g0vhU7v1hRl9v1nGB9V"},
        dataType: "json",
        success: function (res) {
             alert(res.data)

        },
        error: function () {
            alert('error!')
        }
    });
};


function initPayInfo(b2b_order_number) {
    $.ajax({
        type: "post",
        url: "/ylt/initPayInfo",
        data: {
            // "b2b_order_number": "357341",
            "b2b_order_number": "468454",
            "openid":"oU6Tw0GTdJlwZEsBkIR7hre87XJ4",
            "shop_cust_id":"150372101132459","zdkh_userid":"1000000000062965"},
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var trs = new Array();
            var test = $("#orders_line");
            test.empty();
            trs.push("<tr>");
            trs.push('<td><div class="order" >'+ (i+1) + '</div></td>');
            trs.push("<td><div >"+res.data.TOKEN_ID +"</div></td>");
            /*trs.push("<td><div >"+res.data +"</div></td>");*/
            trs.push("</tr>");
            $(trs.join('')).appendTo(test);


        },
        error: function () {
            alert('error!')
        }
    });
};

function getYlt_items() {
    $.ajax({
        type: "post",
        url: "/ylt/getYlt_Order_Item",
        data: JSON.stringify({"B2B_ORDER_NUMBER": "833709","pageNum":1,"pageSize":10,"DATA_TYPE":"order"
         }),
        contentType:"json/application",
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var trs = new Array();
            var test = $("#items_heard");
            test.empty();
            $.each(res.data.list,function (i,item){
                trs.push("<tr>");
                trs.push('<td><div class="order" >'+ (i+1) + '</div></td>');
                trs.push("<td><div >"+item.SHOP_NAME +"</div></td>");
                trs.push("<td><div >"+item.T_ITEM_NAME +"</div></td>");
                trs.push("<td><div >"+item.T_SPEC +"</div></td>");
                trs.push("<td><div >"+item.T_JIXING +"</div></td>");
                trs.push("<td><div >"+item.BZDW +"</div></td>");
                trs.push("<td><div >"+item.T_MEASURE_SPEC +"</div></td>");
                trs.push("<td><div >"+item.T_FACTORY +"</div></td>");
                trs.push("<td><div >"+item.T_APPROVE_DOC +"</div></td>");
                trs.push("</tr>");
            });
            $(trs.join('')).appendTo(test);
        },
        error: function () {
            alert('error!')
        }
    });
};


function ylt_product_registration() {
    $.ajax({
        type: "post",
        url: "/ylt/ylt_product_registration",
        data: {"cust_id": "1000000000062965","item_code": "146846746381581",
            "shop_cust_id": "372000",
            "amount": "5",
            "bz": "测试"
        },
        dataType: "json",
        success: function (res) {
             alert(res.msg);

        },
        error: function () {
            alert('error!')
        }
    });
};


function get_ylt_product_registration() {
    $.ajax({
        type: "post",
        url: "/ylt/get_ylt_product_registration",
        data: {"cust_id": "1000000000062965","pageNum":1,"pageSize":100
        },
        dataType: "json",
        success: function (res) {
            // alert(res.imageInfo.list[0])
            var trs = new Array();
            var test = $("#orders_heard");
            test.empty();
            $.each(res.data.list,function (i,item){
                trs.push("<tr>");
                trs.push('<td><div class="order" >'+ (i+1) + '</div></td>');
                trs.push("<td><div >"+item.TYM +"</div></td>");
                trs.push("<td><div ><a onclick='ylt_cancle_registration(\""+item.REG_ID+"\")' >"+item.REG_ID +"</a></div></td>");
                trs.push("<td><div >"+item.SHOP_NAME +"</div></td>");
                trs.push("<td><div >"+item.STATE +"</div></td>");
                trs.push("</tr>");
            });
            $(trs.join('')).appendTo(test);


        },
        error: function () {
            alert('error!')
        }
    });
};


function ylt_cancle_registration(ITEM_CODE) {
    $.ajax({
        type: "post",
        url: "/ylt/ylt_cancle_registration",
        data: {"reg_id": ITEM_CODE
        },
        dataType: "json",
        success: function (res) {
            alert(res.data);
            get_ylt_product_registration();

        },
        error: function () {
            alert('error!')
        }
    });
};


function ylt_signOrder(ITEM_CODE) {
    $.ajax({
        type: "post",
        url: "/ylt/ylt_signOrder",
        data: {"b2b_order_number": ITEM_CODE
        },
        dataType: "json",
        success: function (res) {
            alert(res.data);
            getYlt_orders_header();

        },
        error: function () {
            alert('error!')
        }
    });
};

function ylt_updateOrderZT(b2b_order_number,so_zt) {
    $.ajax({
        type: "post",
        url: "/ylt/ylt_editOrderZt",
        data: JSON.stringify({"B2B_ORDER_NUMBER": b2b_order_number,"SO_ZT":so_zt
        }),
        dataType: "json",
        success: function (res) {
            alert(res.data);

        },
        error: function () {
            alert('error!')
        }
    });
};

